﻿

CREATE FUNCTION [dbo].[GetStocIntrari]
(
	@IDArticol int,
	@Pret decimal(25,5)	
)
RETURNS decimal(25,5)
AS
BEGIN

	DECLARE @ResultVar decimal(25,5)

	SELECT @ResultVar = COALESCE(SUM(dd.Cantitate),0) FROM DocumenteDetaliu dd JOIN
	Documente d ON d.IDDocument=dd.IDDocument 
	WHERE dd.IDArticol=@IDArticol AND dd.ValoareUnitara = @Pret AND 
	(d.IDTipDocument = 0 OR d.IDTipDocument = 15) AND d.AreDocGestStoc=1

	-- Return the result of the function
	RETURN @ResultVar

END